package com.pipe.protocol.events.other;

import com.pipe.util.MysqlProtocolUtil;
import io.netty.buffer.ByteBuf;

/**
 * @author Kiven
 * @see <a href="https://dev.mysql.com/doc/internals/en/rotate-event.html">mysql internal doc</a>
 *
 */
public class RotateEvent {
    private long postion;
    private String nextBinlogFileName;

    public RotateEvent(long postion, String nextBinlogFileName) {
        this.postion = postion;
        this.nextBinlogFileName = nextBinlogFileName;
    }

    public static RotateEvent build(ByteBuf buf){
        long postion = buf.readLongLE();
        String binlogFile = MysqlProtocolUtil.readStringFromBytebuf(buf);
        return new RotateEvent(postion, binlogFile);
    }

    @Override
    public String toString() {
        return "{" +
                "postion=" + postion +
                ", nextBinlogFileName='" + nextBinlogFileName + '\'' +
                '}';
    }
}